snapshot: Directly clip color nodes
authorTimm Bäder <mail@baedert.org>
Tue, 12 Dec 2017 19:33:53 +0000 (20:33 +0100)
committerTimm Bäder <mail@baedert.org>
Thu, 21 Dec 2017 17:25:52 +0000 (18:25 +0100)
Clipping a color node is trivial so we do it here directly since that
might later save the entire clip node as well as freeing the fragment
shaders from coloring lots of pixels that will be clipped away.

gtk/gtksnapshot.c

index d632ef6364fec0129fbd4fc07923c59fc6c37346..c3f9295045cb904c3b10f55e07c0aab406d2d064 100644 (file)
@@ -1345,7 +1345,23 @@ gtk_snapshot_append_color (GtkSnapshot           *snapshot,
   g_return_if_fail (color != NULL);
   g_return_if_fail (bounds != NULL);
 
+
   graphene_rect_offset_r (bounds, current_state->translate_x, current_state->translate_y, &real_bounds);
+
+  /* Color nodes are trivially "clippable" so we do it now */
+  if (current_state->clip_region)
+    {
+      cairo_rectangle_int_t clip_extents;
+      cairo_region_get_extents (current_state->clip_region, &clip_extents);
+      graphene_rect_intersection (&GRAPHENE_RECT_INIT (
+                                    clip_extents.x,
+                                    clip_extents.y,
+                                    clip_extents.width,
+                                    clip_extents.height
+                                  ),
+                                  &real_bounds, &real_bounds);
+    }
+
   node = gsk_color_node_new (color, &real_bounds);
 
   if (name && snapshot->record_names)